home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / OrganicTreeUI.java < prev    next >
Text File  |  1998-06-30  |  4KB  |  121 lines

  1. /*
  2.  * @(#)OrganicTreeUI.java    1.8 98/02/02
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. package com.sun.java.swing.plaf.organic;
  22.  
  23. import com.sun.java.swing.*;
  24. import com.sun.java.swing.event.*;
  25. import com.sun.java.swing.text.DefaultTextUI;
  26. import java.awt.*;
  27. import java.awt.event.*;
  28. import java.beans.*;
  29. import java.io.*;
  30. import java.util.*;
  31. import com.sun.java.swing.plaf.ComponentUI;
  32. import com.sun.java.swing.plaf.TreeUI;
  33. import com.sun.java.swing.tree.*;
  34.  
  35. import com.sun.java.swing.plaf.basic.*;
  36.  
  37. /**
  38.  * Organic L&F for a tree component.
  39.  * <p>
  40.  * Warning: serialized objects of this class will not be compatible with
  41.  * future swing releases.  The current serialization support is appropriate
  42.  * for short term storage or RMI between Swing1.0 applications.  It will
  43.  * not be possible to load serialized Swing1.0 objects with future releases
  44.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  45.  * baseline for the serialized form of Swing objects.
  46.  *
  47.  * @version 1.14 01/13/98
  48.  * @author Tom Santos
  49.  */
  50. public class OrganicTreeUI extends BasicTreeUI {
  51.  
  52.     // Boilerplate
  53.     public static ComponentUI createUI(JComponent x) {
  54.     return new OrganicTreeUI();
  55.     }
  56.  
  57.     public OrganicTreeUI()
  58.     {
  59.     super();
  60.     }
  61.  
  62.     protected int getHorizontalLegBuffer()
  63.       {
  64.     return 3;
  65.       } 
  66.  
  67.     public void installUI( JComponent c ) {
  68.         super.installUI( c );
  69.     if ( !tree.isLargeModel() ) {
  70.         setRowHeight( 0 );
  71.     }
  72.     }
  73.  
  74.     protected boolean clickedInExpandControl( VisibleTreeNode node, LargeTreeModelNode eNode,
  75.                           int row, int rowLevel, int mouseX, int mouseY )
  76.       {
  77.     if ( node != null && node.isLeaf() )
  78.       {
  79.         return false;
  80.       }
  81.  
  82.     int                     boxWidth;
  83.  
  84.     if(getExpandedIcon() != null)
  85.         boxWidth = getExpandedIcon().getIconWidth() + 6;
  86.     else
  87.         boxWidth = 8;
  88.     int    boxLeftX;
  89.     if(this.getShowsRootHandles())
  90.         boxLeftX = ((rowLevel * totalChildIndent) +
  91.             getLeftChildIndent()) - boxWidth/2;
  92.     else
  93.         boxLeftX = (((rowLevel - 1) * totalChildIndent) +
  94.             getLeftChildIndent()) - boxWidth/2;
  95.     int boxRightX = boxLeftX + boxWidth;
  96.     
  97.     return mouseX >= boxLeftX && mouseX <= boxRightX;
  98.       }
  99.  
  100.     static protected final int SIZE = 3;
  101.  
  102.     /**
  103.      * Icon that displays the expanded or collapsed state of a node.
  104.      * <p>
  105.      * Warning: serialized objects of this class will not be compatible with
  106.      * future swing releases.  The current serialization support is appropriate
  107.      * for short term storage or RMI between Swing1.0 applications.  It will
  108.      * not be possible to load serialized Swing1.0 objects with future releases
  109.      * of Swing.  The JDK1.2 release of Swing will be the compatibility
  110.      * baseline for the serialized form of Swing objects.
  111.      */
  112.     public static class ExpandCollapseIcon implements Icon, Serializable {
  113.     public void paintIcon(Component c, Graphics g, int x, int y) {
  114.         g.setColor( UIManager.getColor("Tree.knobColor") );
  115.         g.fillRect( x, y, SIZE, SIZE );
  116.     }
  117.     public int getIconWidth() { return SIZE; }
  118.     public int getIconHeight() { return SIZE; }
  119.     }
  120. }
  121.